﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClient;

namespace HF.Framework.DataClientDBAgent
{
    public class ClientDBAgent
    {
        private DataClientType _dataClientType;
        private IDatabase _dataBase;
        public DataClientType DataClientType
        {
            get { return _dataClientType; }
            set { _dataClientType = value; }

        }
      
        public IDatabase Database
        {
            get { return _dataBase; }
            set { _dataBase = value; }
        }
        public ClientDBAgent()
        {

            _dataBase = new DataProvider();

        }
        public  DbConnectionType GetDbConnectionType()
        {
           return DbConnectionType.Normal; 
        }

        public int ExecuteNonQuery(SqlDataItem sqlItem)
        {

            return _dataBase.ExecuteNonQuery(sqlItem);

        }
        public bool ExecuteNonQueryArray(SqlDataItemArray arySqlDataItem)
        {
            return _dataBase.ExecuteNonQueryArray(arySqlDataItem);
        }
        public DataTable ExecuteDataTable(SqlDataItem sqlItem)
        {
            return _dataBase.ExecuteDataTable(sqlItem);
        }
        public DataSet ExecuteQuery(SqlDataItem sqlItem)
        {
            return _dataBase.ExecuteQuery(sqlItem);
        }
        public string ExecuteScalar(SqlDataItem sqlDataItem)
        {
            return _dataBase.ExecuteScalar(sqlDataItem);
        }
        public bool RecordExists(SqlDataItem sqlItem)
        {
            return _dataBase.RecordExists(sqlItem);
        }
       
        #region 更新数据集
        public void UpdateDataSetWithTranse(DataSet ds)
        {
            UpdateDataSetWithTranse(ds, null);
        }
        public void UpdateDataTableWithTranse(DataTable dataTable)
        {
            UpdateDataTableWithTranse(dataTable, null);
        }
        /// <summary>
        /// 更新数据集，启动数据库事务
        /// </summary>
        /// <param name="ds">数据集</param>
        /// <param name="databaseName">数据库名</param>
        public void UpdateDataSetWithTranse(DataSet dataSet, string databaseName)
        {
            _dataBase.UpdateDataSetWithTranse(dataSet, databaseName);
        }
        /// <summary>
        /// 更新表,启动数据库事务
        /// </summary>
        /// <param name="dataTable">要更新的表</param>
        /// <param name="databaseName">数据库名</param>
        public void UpdateDataTableWithTranse(DataTable dataTable, string databaseName)
        {
            _dataBase.UpdateDataTableWithTranse(dataTable, databaseName);
        }


        #endregion

        #region 获得一个空结构
        public DataTable GetBlankTable(string tableName)
        {
            return GetBlankTable(tableName, null);
        }
        public DataSet GetBlankDataSet(List<string> tableNames)
        {
            return GetBlankDataSet(tableNames, null);
        }
        public DataTable GetBlankTable(string tableName, string databaseName)
        {
            return _dataBase.GetBlankTable(tableName,databaseName);
        }
        public DataSet GetBlankDataSet(List<string> tableNames, string databaseName)
        {
            return _dataBase.GetBlankDataSet(tableNames,databaseName);
        }
        #endregion

        #region 访问当前数据库的表和字段
        public string GetCurrentDatabaseName()
        {
            return _dataBase.GetCurrentDatabaseName();
        }
        public DataSet GetDBQuery(string databaseName)
        {
            return _dataBase.GetDBQuery(databaseName);
        }
        public DataTable GetDBDataTable(string databaseName)
        {
            return _dataBase.GetDBDataTable(databaseName);
        }
        public DataSet GetDTColumnsQuery(string tableName, string databaseName)
        {
            return _dataBase.GetDTColumnsQuery(tableName, databaseName);
        }
        public DataTable GetDTColumnsDataTable(string tableName, string databaseName)
        {
            return _dataBase.GetDTColumnsDataTable(tableName, databaseName);
        }
        public string GetDBDateTime()
        {
            return _dataBase.GetDBDateTime();
        }
        #endregion
        
    }
    public enum DataClientType
    {
        SQLSERVER,
        ORACLE,
        ACCESS
    }
}
